/*
 * Administrador de la interfaz grafica
 */
package huetari.gui;

import huetari.logic.Matriz;
import java.util.LinkedList;

/**
 * Ventana Principal
 * @author MaNu
 */

public class VentanaPrincipal extends javax.swing.JFrame {

    /**
     * Crea un nuevo form VentanaPrincipal
     */
    public VentanaPrincipal() {
        initComponents(); // Pone los componentes en el frame
        PanelOP.setEnabled(true);// Desabilita el panel de opciones
        jTextPane1.setVisible(false);
        BotonDebug.setVisible(false);
        jTextPane1.setEditable(false);
        setVisible(true);// Setea la ventana para ser visible
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PanelDE = new javax.swing.JPanel();
        BotonDebug = new javax.swing.JButton();
        PanelDebug = new javax.swing.JScrollPane();
        jTextPane1 = new javax.swing.JTextPane();
        PanelIZ = new javax.swing.JScrollPane();
        PanelFichas = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        PanelOP = new javax.swing.JTabbedPane();
        PanelConfig = new javax.swing.JPanel();
        BotonAceptar = new javax.swing.JButton();
        ScrollTabla = new javax.swing.JScrollPane();
        TablaConfig = new javax.swing.JTable();
        PanelMain = new javax.swing.JScrollPane();
        MainCampo = new javax.swing.JPanel();
        PanelDebugger = new javax.swing.JScrollPane();
        Menu = new javax.swing.JMenuBar();
        MenuArchivo = new javax.swing.JMenu();
        ArchivoNuevo = new javax.swing.JMenuItem();
        ArchivoGuardar = new javax.swing.JMenuItem();
        ArchivoSalir = new javax.swing.JMenuItem();
        MenuModo = new javax.swing.JMenu();
        ModoHardware = new javax.swing.JCheckBoxMenuItem();
        ModoSoftware = new javax.swing.JCheckBoxMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setBackground(java.awt.Color.white);
        setForeground(java.awt.Color.white);
        setMinimumSize(new java.awt.Dimension(1150, 700));
        setPreferredSize(new java.awt.Dimension(1150, 700));
        setResizable(false);

        PanelDE.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        BotonDebug.setText("Debug");

        PanelDebug.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        jTextPane1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        PanelDebug.setViewportView(jTextPane1);

        javax.swing.GroupLayout PanelDELayout = new javax.swing.GroupLayout(PanelDE);
        PanelDE.setLayout(PanelDELayout);
        PanelDELayout.setHorizontalGroup(
            PanelDELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelDELayout.createSequentialGroup()
                .addContainerGap(152, Short.MAX_VALUE)
                .addComponent(BotonDebug)
                .addContainerGap())
            .addGroup(PanelDELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(PanelDELayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(PanelDebug, javax.swing.GroupLayout.DEFAULT_SIZE, 198, Short.MAX_VALUE)
                    .addContainerGap()))
        );
        PanelDELayout.setVerticalGroup(
            PanelDELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelDELayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(BotonDebug)
                .addContainerGap())
            .addGroup(PanelDELayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(PanelDELayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(PanelDebug, javax.swing.GroupLayout.PREFERRED_SIZE, 557, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(49, Short.MAX_VALUE)))
        );

        PanelIZ.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        PanelFichas.setBackground(java.awt.SystemColor.text);
        PanelFichas.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        PanelFichas.setForeground(java.awt.SystemColor.text);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/Inicio.png"))); // NOI18N

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/icons/TuboVertical.png"))); // NOI18N

        javax.swing.GroupLayout PanelFichasLayout = new javax.swing.GroupLayout(PanelFichas);
        PanelFichas.setLayout(PanelFichasLayout);
        PanelFichasLayout.setHorizontalGroup(
            PanelFichasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelFichasLayout.createSequentialGroup()
                .addContainerGap(28, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addGap(33, 33, 33))
        );
        PanelFichasLayout.setVerticalGroup(
            PanelFichasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelFichasLayout.createSequentialGroup()
                .addGroup(PanelFichasLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING))
                .addGap(0, 587, Short.MAX_VALUE))
        );

        PanelIZ.setViewportView(PanelFichas);

        PanelOP.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        PanelConfig.setBackground(javax.swing.UIManager.getDefaults().getColor("white"));
        PanelConfig.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        BotonAceptar.setText("Aceptar");

        ScrollTabla.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        TablaConfig.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Salida", "Pin Arduino", "Descripci��n"
            }
        ));
        ScrollTabla.setViewportView(TablaConfig);

        javax.swing.GroupLayout PanelConfigLayout = new javax.swing.GroupLayout(PanelConfig);
        PanelConfig.setLayout(PanelConfigLayout);
        PanelConfigLayout.setHorizontalGroup(
            PanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(PanelConfigLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(PanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(ScrollTabla, javax.swing.GroupLayout.DEFAULT_SIZE, 316, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelConfigLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(BotonAceptar)))
                .addContainerGap())
        );
        PanelConfigLayout.setVerticalGroup(
            PanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PanelConfigLayout.createSequentialGroup()
                .addGap(177, 177, 177)
                .addComponent(ScrollTabla, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 175, Short.MAX_VALUE)
                .addComponent(BotonAceptar)
                .addContainerGap())
        );

        PanelOP.addTab("Configuraci��n", PanelConfig);

        PanelMain.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        MainCampo.setBackground(javax.swing.UIManager.getDefaults().getColor("white"));
        MainCampo.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));

        javax.swing.GroupLayout MainCampoLayout = new javax.swing.GroupLayout(MainCampo);
        MainCampo.setLayout(MainCampoLayout);
        MainCampoLayout.setHorizontalGroup(
            MainCampoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 344, Short.MAX_VALUE)
        );
        MainCampoLayout.setVerticalGroup(
            MainCampoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 620, Short.MAX_VALUE)
        );

        PanelMain.setViewportView(MainCampo);

        PanelOP.addTab("Main", PanelMain);

        PanelDebugger.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        PanelOP.addTab("Debugger", PanelDebugger);

        MenuArchivo.setText("Archivo");

        ArchivoNuevo.setText("Nuevo");
        MenuArchivo.add(ArchivoNuevo);

        ArchivoGuardar.setText("Guardar");
        MenuArchivo.add(ArchivoGuardar);

        ArchivoSalir.setText("Salir");
        ArchivoSalir.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                ArchivoSalirMouseClicked(evt);
            }
        });
        MenuArchivo.add(ArchivoSalir);

        Menu.add(MenuArchivo);

        MenuModo.setText("Modo");

        ModoHardware.setText("Hardware");
        MenuModo.add(ModoHardware);

        ModoSoftware.setText("Software");
        MenuModo.add(ModoSoftware);

        Menu.add(MenuModo);

        setJMenuBar(Menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(PanelIZ, javax.swing.GroupLayout.PREFERRED_SIZE, 227, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(PanelOP, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(PanelDE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(23, 23, 23))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(PanelOP, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                    .addComponent(PanelIZ, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 624, Short.MAX_VALUE)
                    .addComponent(PanelDE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(43, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ArchivoSalirMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_ArchivoSalirMouseClicked
        System.exit(0);
    }//GEN-LAST:event_ArchivoSalirMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VentanaPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new VentanaPrincipal().setVisible(true);
            }
        });
    }
    
    /**
 *Este metodo se encarga de hacer los cambios respectivos cuando se cambia de pestania
 *en la aplicacion.
 *
 *@param evt 
 */    
    private void CambioDePestanias(javax.swing.event.ChangeEvent evt) {                                   
        int indicePestania = PanelOP.getSelectedIndex();
        if(PanelOP.getTabCount() != 1)
        {
            if(indicePestania == 0)
            {
                debuger = true;
                jTextPane1.setVisible(false);
                BotonDebug.setVisible(false);
                setModo();
            }
            else if(indicePestania == 1)
            {
                setModo();
                jTextPane1.setVisible(false);
                BotonDebug.setVisible(false);
                PanelMain.setViewportView(MainCampo);
                debuger = false;
            }
            else
            {
                setModo();
                jTextPane1.setVisible(true);
                BotonDebug.setVisible(true);
                PanelDebugger.setViewportView(MainCampo);
                debuger = true;
            }
        }
    }
    
    /**
     * Este metodo se encarga de cambiar el valor de la variable modo dependiendo
     * de la seleccion que haya hecho el usuario.
     */
    private void setModo()
    {
            if(ModoHardware.isSelected())
            {
                modo = false;
            }
            else if(ModoSoftware.isSelected())
            {
                modo = true;
            }
    }

    /**
     * Este metodo se encarga de retornar la variable privada modo.
     */
    public boolean getModo()
    {
        return modo;
    }

    /**
     * Este metodo se encarga de retornar la variable privada empezo
     */
    public boolean getempezo()
    {
        return empezo;
    }

    /*public void setMatriz(Matriz pMatriz)
    {
        miMatriz = pMatriz;
    }*/

    public boolean isDebuger()
    {
        return debuger;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem ArchivoGuardar;
    private javax.swing.JMenuItem ArchivoNuevo;
    private javax.swing.JMenuItem ArchivoSalir;
    private javax.swing.JButton BotonAceptar;
    private javax.swing.JButton BotonDebug;
    private javax.swing.JPanel MainCampo;
    private javax.swing.JMenuBar Menu;
    private javax.swing.JMenu MenuArchivo;
    private javax.swing.JMenu MenuModo;
    private javax.swing.JCheckBoxMenuItem ModoHardware;
    private javax.swing.JCheckBoxMenuItem ModoSoftware;
    private javax.swing.JPanel PanelConfig;
    private javax.swing.JPanel PanelDE;
    private javax.swing.JScrollPane PanelDebug;
    private javax.swing.JScrollPane PanelDebugger;
    private javax.swing.JPanel PanelFichas;
    private javax.swing.JScrollPane PanelIZ;
    private javax.swing.JScrollPane PanelMain;
    private javax.swing.JTabbedPane PanelOP;
    private javax.swing.JScrollPane ScrollTabla;
    private javax.swing.JTable TablaConfig;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JTextPane jTextPane1;
    // End of variables declaration//GEN-END:variables

    // Otras variables
    private boolean modo = false;
    private boolean debuger = true;
    private boolean empezo = false;
    private int posXTem;
    private int posYTem;
    private javax.swing.JLabel labelTem;
    private Matriz miMatriz;
    private LinkedList<javax.swing.JLabel> Fichas1;
    private LinkedList<javax.swing.JLabel> Fichas2;
    private LinkedList<javax.swing.JLabel> Fichas3;
    private LinkedList<javax.swing.JLabel> Fichas4;
    private LinkedList<javax.swing.JLabel> Fichas5;
    private LinkedList<javax.swing.JLabel> Fichas6;
    private LinkedList<javax.swing.JLabel> Fichas7;
    private LinkedList<javax.swing.JLabel> Fichas8;
    private LinkedList<String> variables;
    LinkedList<String> OrdenLeds;
    LinkedList<Integer> Temporal;

}
